import Packet from "../net/Packet"

// 随机名字
export default class AccountRandName {
	/**
	 * @param sid 服务器ID
	 * @param sex 性别
	 */
	public constructor(public sid: number, public sex: number) { }

	public encode(): Packet {
		const packet = this._encode()
		packet.Encode(2050)
		return packet
	}

	public encodeMsg(): ByteBuffer {
		return this._encode().GetBuffer()
	}

	public static decode(packet: Packet): AccountRandName {
		const sid = packet.ReadUshort()
		const sex = packet.ReadByte()
		return new AccountRandName(sid, sex)
	}

	private _encode(): Packet {
		const packet = new Packet()
		packet.WriteUshort(this.sid)
		packet.WriteByte(this.sex)
		return packet
	}
}
